package com.freesky.web.manager.controller.item;

import com.freesky.common.pojo.ZTreeNode;
import com.freesky.common.utils.reponse.JSONResponse;
import com.freesky.common.dao.entity.ItemCat;
import com.freesky.web.manager.remote.order.ItemCatRemote;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author Freesky
 * @date 2017/8/2
 */
@Controller
@RequestMapping("/item/cat")
@Api(description = "商品分类信息")
public class ItemCatController {

    @Autowired
    private ItemCatRemote itemCatRemote;


    @GetMapping("/page")
    public String page() {
        return "item/item-cat/list";
    }

    @GetMapping("/choose/category")
    public String chooseCat() {
        return "item/item-cat/choose-category";
    }

    @GetMapping("/choose/category/parent")
    public String chooseParentCat() {
        return "item/item-cat/choose-parent-category";
    }

    @GetMapping("/add")
    public String add() {
        return "item/item-cat/add";
    }

    @ResponseBody
    @GetMapping(value = "/list")
    @ApiOperation(value = "通过父ID获取商品分类列表")
    public List<ZTreeNode> getItemCatList(@RequestParam(name="id",defaultValue = "0") int parentId){
        return itemCatRemote.getItemCatList(parentId);
    }

    @ResponseBody
    @PutMapping(value = "/add")
    @ApiOperation(value = "添加商品分类")
    public JSONResponse addItemCategory(@ModelAttribute ItemCat itemCat){
        return itemCatRemote.addItemCategory(itemCat);
    }

    @ResponseBody
    @PostMapping(value = "/update")
    @ApiOperation(value = "编辑商品分类")
    public JSONResponse updateItemCategory(@ModelAttribute ItemCat itemCat){

        return itemCatRemote.updateItemCategory(itemCat);
    }

    @ResponseBody
    @DeleteMapping(value = "/del/{id}")
    @ApiOperation(value = "删除商品分类")
    public JSONResponse deleteItemCategory(@PathVariable(value = "id") Long id){
        return itemCatRemote.deleteItemCategory(id);
    }
}
